<?php

include_once ('bn_path.php');

class bn_rolname
{

    private $dl;
    private $gf;
    protected static $instance;

    function __construct()
    {
        $this->dl = new bn_dal();
        $this->gf=new bn_genralfunc;
    }


    public static function getInstance()
    {
        if (!isset(self::$instance))
        {
            self::$instance = new self();
        }
        return self::$instance;
    }


    public function insert($name)
    {
        if (self::has_rolname($name))
            return 2;
        else
        {
            $this->dl->query('insert into rolname(name)values(?)', func_get_args());
            return 1;
        }
    }

    public function delete($id)
    {
        if ($id > 4)
        {
            $this->dl->delete('rolname', $id);
            return 1;
        } else
            return 2;
    }

    public function update($name, $id)
    {
        if (self::has_rolname($name))
            return 2;
        else
        {
            $this->dl->update('rolname', array('name' => $name), array('id=' => $id));
            return 1;
        }
    }

    public function select($name = '')
    {
        if ($name == '')
            return $this->dl->select('select * from rolname');
        else
            return $this->dl->Select('select id,name from rolname where name=?',
                func_get_args());
    }

    public function has_rolname($name)
    {
        return $this->dl->hasrow('select name from rolname where name=?', $name);
    }

    public function id2rolname($id)
    {
        return $this->dl->getvalue('select name from rolname where id=?', $id);
    }

    public function lbx_rolname($args=array('name' => 'rolnamelbx','text'=>'name','value'=>'id','cssclass'=>'select'))
    {
        $list = new bn_listbox();
        $this->gf->class_property($list,$args);
        echo $list->show(self::select()->fetch());
    }

    public function ddl_rolename($args=array('name' => 'rolenameddl','text'=>'name','value'=>'id','cssclass'=>'select'))
    {
        $list = new bn_DropDownList();
        $this->gf->class_property($list,$args);
        echo $list->show(self::select()->fetch());
    }

    function _destruct()
    {
        unset($this->dl);
        unset($this->gf);
    }
}

?>